package com.tanhua.server.interceptor;

import com.tanhua.model.domain.User;

public class UserHolder {

    private static ThreadLocal<User> tl = new ThreadLocal<>();
    //将用户对象存入 ThreadLocal
    public static void set(User  user){
        tl.set(user);
    }
    //从当前线程获取用户对象
    public static User get(){
        return tl.get();
    }
    //从当前线程，获取用户对象的id
    public static Long getUserId() {
        return tl.get().getId();
    }

    //从当前用户获取手机号码
    public static String getPhone(){
        return tl.get().getMobile();
    }
    //清空
    public static void remove(){
        tl.remove();
    }
}
